#!/bin/sh

git_ssh_url=$1
tagname=$2

pid_file=/tmp/main_service.pid
if [ -f $pid_file ]; then
kill -9 `cat $pid_file`
fi

cd ~
if [ -d $tagname ]; then
    rm -rf $tagname
fi

git clone $git_ssh_url $tagname
cd $tagname
git checkout $tagname -b branch_$tagname
rm -rf .git *.md docs
cd src
python -m compileall server/
cd server
find . -type f -name "*.py" -exec rm {} \;

#nohup python main_service.pyc --debug=true --port=18602 --logging=debug --log_file_prefix=push_log &
nohup python main_service.pyc --debug=true --logging=debug --log_file_prefix=push_log &
echo $! > $pid_file

nohup python mqtt_service.pyc > /dev/null 2>&1 &
echo $! >> $pid_file
